package com.ruoyi.app.utils;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;
import java.util.Set;

public class SmsUtil {


    /**
     * 发送验证码
     *
     * @param phone
     * @param code
     */
    public static boolean sendCode(String phone, String code) {
        String serverIp = "app.cloopen.com";
        //请求端口
        String serverPort = "8883";
        //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
        String accountSId = "8a216da86077dcd001609c45951e1659";
        String accountToken = "03b4fb3d4aab4941a5b5e31673691eed";
        //请使用管理控制台中已创建应用的APPID
        String appId = "8aaf07086077a6e60160a022044413dc";
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
        String templateId = "227083";
        String[] datas = {code, "5"};
        HashMap<String, Object> result = sdk.sendTemplateSMS(phone, templateId, datas);
        if ("000000".equals(result.get("statusCode"))) {
            //正常返回输出data包体信息（map）
            return true;
        } else {
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") + " 错误信息= " + result.get("statusMsg"));
            return false;
        }
    }




    public static void main(String[] args) {
        sendCode("15688413831", "123456");
    }


}
